package com.neusoft.yuejian12.yuejian_12.adapter;

import android.content.Context;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.javabean.CommentBean;
import com.neusoft.yuejian12.yuejian_12.javabean.PostBean;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.neusoft.yuejian12.yuejian_12.constant.Constant.USER_PHOTO_URL;

/**
 * Created by hp on 2017/10/30.
 */

public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflaterp;

    public CommentListAdapter(Context mContext,List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflaterp = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflaterp.from(parent.getContext())
                .inflate(R.layout.cardview_comment, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final CommentBean entity = (CommentBean) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.userName.setText(entity.getU_name());
        viewHolder.commentInfo.setText(entity.getInfo());
        viewHolder.Time.setText(entity.getCreattime());

        //  Log.d("w","consultInfo");
        String UserPic = USER_PHOTO_URL + entity.getU_pic();
        Picasso.with(mContext).load(UserPic).into(viewHolder.userPic);
        if (viewHolder.userPic.getDrawable() == null) {
            viewHolder.userPic.setImageResource(R.drawable.ic_add);
        }
    }

    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView userPic;
        TextView Time;
        TextView userName;
        TextView commentInfo;


        public ViewHolder(View itemView) {
            super(itemView);
            userName = (TextView) itemView.findViewById(R.id.comusername);
            commentInfo= (TextView) itemView.findViewById(R.id.commentinfo);
            Time = (TextView) itemView.findViewById(R.id.commenttime);
            userPic = (ImageView) itemView.findViewById(R.id.comuserpic);

        }
    }
}
